<template>
    <div>
      <h3>发布公告</h3>
      <el-form :model="createAnnouncementForm" :rules="rules" class="login-container" label-position="left" label-width="0px" ref="createAnnouncementForm">
        <el-form-item prop="content">
          <el-input type="textarea"
                    :rows="2"
                    v-model="createAnnouncementForm.content" auto-complete="off" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item style="width: 30%">
          <el-button type="primary"  @click="handleAnnouncementSubmit" style="width: 100%">提交更新</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
export default {
  name: 'Admin',
  data () {
    return {
      createAnnouncementForm: {
        content: ''
      },
      rules: {
        content: [
          { required: true, message: '请输入内容', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    handleAnnouncementSubmit () {
      this.$refs.createAnnouncementForm.validate((valid) => {
        if (valid) {
          this.$axios.post('/notification/system_announcement_create',
            {
              content: this.createAnnouncementForm.content,
              relatedUserId: this.$store.getters.getCurrentUserId
            },
            { headers: { Authorization: this.$store.state.jwt } })
            .then(response => {
              this.resetForm()
            })
        } else {
          return false
        }
      })
    },
    resetForm () {
      this.$refs.createAnnouncementForm.resetFields()
    }
  }
}
</script>

<style scoped>

</style>
